﻿# -*- coding: utf-8 -*-
"""
并发抓取 10 个 url，并且打印出它们的状态码、和文本内容
"""
import concurrent.futures
import requests


def get_url_data(url):
    r = requests.get(url)
    print('#' * 40)
    print('--->', url)
    print('状态码：', r.status_code)
    print('文本内容：', r.text)


def run(url_list):
    if url_list:
        with concurrent.futures.ThreadPoolExecutor(3) as pool:
            for i in url_list:
                pool.submit(get_url_data, i)


if __name__ == '__main__':
    url_list = [
        'https://mirrors.aliyun.com/centos/7/os/',
        'https://mirrors.aliyun.com/centos/6/',
        'https://mirrors.aliyun.com/centos/5/',
        'https://mirrors.aliyun.com/epel/7/x86_64/',
        'https://mirrors.aliyun.com/epel/7/x86_64/debug/',
        'https://mirrors.aliyun.com/epel/7/x86_64/drpms/',
        'https://mirrors.aliyun.com/mongodb/yum/',
        'https://mirrors.aliyun.com/kubernetes/',
        'https://mirrors.aliyun.com/zabbix/zabbix/5.5/',
        'https://mirrors.aliyun.com/ros/ubuntu/'
    ]
    run(url_list)
